'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview battle
 * @author sundbcn@gmail.com (sun debing)
 */

var moment = require('moment');
var _ = require('lodash');
var dataApi = require('../libs/dataApi');

/**
 * 获官阶商品配置
 */
exports.getPvpShopRewardConf = function (job_type, property_id) {
    return _getShopConf(job_type, property_id);
};

/**
 * 获官阶商品价格
 */
exports.getPvpShopRewardPrice = function (job_type, property_id) {
    var shop_conf = _getShopConf(job_type, property_id);
    return {
        cost_coin: shop_conf.cost_coin,
        cost_point: shop_conf.cost_point
    };
};

/**
 * 获取官阶俸禄配置
 */
exports.getSalaryRewardConf = function (job_type, noble) {
    var noble_reward = dataApi.pvp_position_reward.findById(noble);

    if (!noble_reward) {
        console.error('getSalaryRewardConf() noble id can not found:' + noble);
        return;
    }

    return _.filter(noble_reward, {
        job_type: job_type
    });
};

/**
 * 获取进阶新官阶奖励
 */
exports.getFirstPositionReward = function (job_type, noble) {
    var noble_reward = dataApi.position_first_reward.findById(noble);
    if (!noble_reward) {
        console.error('getFirstPositionReward() noble id can not found:' + noble);
        return;
    }

    return _.filter(noble_reward, {
        job_type: job_type
    });
};

/**
 * 获取官阶配置
 */
exports.getNobleConf = function (noble) {
    var noble_conf = _getNobleConf(noble);
    if (!noble_conf) {
        console.error('noble_conf id can not found:' + noble);
        return;
    }
    return noble_conf;
};

/**
 * 获取掠夺奖励配置
 */
exports.getPvpPrizeConf = function (reward_lv) {
    return dataApi.pvp_prize.findById(reward_lv);
};

/**
 * 获取掠夺商店配置
 */
var _getShopConf = function (job_type, property_id) {
    var shop_conf_list = dataApi.pvp_shop.findById(job_type);
    var shop_conf;
    if (!shop_conf_list) {
        console.error('property id can not found:' + property_id);
        return;
    }

    _.some(shop_conf_list, function (shop_item) {
        if (shop_item.reward == property_id) {
            shop_conf = shop_item;
            return;
        }
    });
    return shop_conf;
};

/**
 * 获取官阶配置
 */
var _getNobleConf = function (noble) {
    var noble_conf = dataApi.pvp_position.findById(noble);
    if (!noble_conf) {
        console.error('noble id can not found:' + noble);
        return;
    }
    return noble_conf;
};
